package pingji.controller.query;

import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pingji.controller.query.ResultObject.QueryOrderObject;
import pingji.pojo.QueryOrderListObject;
import pingji.service.query.QueryOrderService;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@Log
public class QueryOrderController {
    @Autowired
    QueryOrderService service;
    @RequestMapping("/query/all")
    public QueryOrderObject queryOrderByUserId(@RequestParam("id") Integer id){
        QueryOrderObject o=new QueryOrderObject();
        if(id==null){
            o.setCode(-1);
            o.setLength(0);
            o.setList(null);
        }
        else{
            o.setCode(0);
            o.setList(service.queryByUserId(id));
            o.setLength(o.getList().size());
        }
        return o;
    }

    @RequestMapping("/query/all_order")
    public QueryOrderObject queryOrderAll(@RequestParam("id") Integer id){
        QueryOrderObject o=new QueryOrderObject();
        if(id==null){
            o.setCode(-1);
            o.setLength(0);
            o.setList(null);
        }
        else{
            o.setCode(0);
            o.setList(service.queryAllOrder(id));
            o.setLength(o.getList().size());
        }
        return o;
    }
}
